package com.fyt.ZhongYaoApp.Controller;

import com.fyt.ZhongYaoApp.pojo.PageBean;
import com.fyt.ZhongYaoApp.pojo.Result;
import com.fyt.ZhongYaoApp.pojo.ZY;
import com.fyt.ZhongYaoApp.pojo.pg.ZYPG;
import com.fyt.ZhongYaoApp.pojo.vo.ZYQuerry;
import com.fyt.ZhongYaoApp.pojo.vo.ZYVO;
import com.fyt.ZhongYaoApp.service.ZYService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/zy")
@Tag(name = "ZY",description = "the ZY  API") // 接口大标题
public class ZYController {

    @Autowired
    private ZYService zyService;


    @PostMapping("/add")
    public Result add(@RequestBody ZY zy) {

        zyService.add(zy);
        return Result.success("添加成功");
    }

    /**
     * 拿到全部中药
     * @return
     */
    @GetMapping("/list")
    public Result<List<ZYQuerry>> ZYlist() {
        List<ZYQuerry> list = zyService.ZYList();
        return Result.success(list);
    }

    /**
     * 根据种类查询中药列表
     * @return
     */
    @GetMapping("/listByCat")
    public Result<PageBean<ZYQuerry>> ZYListByCat(@RequestBody ZYPG zypg) {

        ZY zy = new ZY();
        BeanUtils.copyProperties(zypg,zy);
        PageBean<ZYQuerry> list = zyService.ZYListByCat(zypg.getPageNum(),zypg.getPageSize(),zy);

        return Result.success(list);
    }

    /**
     * 根据种类查询部分中药信息
     * @return
     */
    @PostMapping("/listPartByCat")
    public Result<PageBean<ZYVO>> ZYListPartByCat(@RequestBody ZYPG zypg) {

        ZY zy = new ZY();
        BeanUtils.copyProperties(zypg,zy);
        PageBean<ZYVO> list = zyService.ZYListPartByCat(zypg.getPageNum(),zypg.getPageSize(),zy);

        return Result.success(list);
    }

    /**
     * 根据中药id获得中药详情
     * @return
     */
    @GetMapping("/findById")
    public Result<ZYQuerry> ZYfindById(@RequestBody ZY zy) {

        ZYQuerry zyQuerry = zyService.findZYById(zy.getId());
        return Result.success(zyQuerry);
    }
}
